<?php
class Admincpanel_Model_Privilege extends Zend_Db_Table
{
	protected $_db;
	
	public function __construct($arrParam = null)
	{
		$this->_db = Zend_Registry::get('connectDb');
	}
	
	public function getScripts()
	{
		$select = $this->_db->select()
				->distinct()
				->from('privileges as p', array('controller'));
		$result = $this->_db->fetchAll($select);
		
		$view = array();
		if ( ! empty($result))
		{
			$i = 0;
			foreach ($result as $row)
			{
				$view[$i]['controller'] = $row['controller'];
				$view[$i]['action'] = $this->getAction($row['controller']);
				$i++;
			}
		}
		return $view;
	}
	
	private function getAction($controller)
	{
		$select = $this->_db->select()
				->from('privileges as p', array('name', 'action'))
				->where('controller = ?', $controller, STRING);
		$result = $this->_db->fetchAll($select);
		return $result;	
	}
}